<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/11/6
 * Time: 14:39
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\admin\controller;

use app\common\business\PlaceOrder;
use app\common\lib\Time;

class Welcome extends Base
{
    public function index(){
        $today = Time::today();
        $where = [
            ['create_time','between',$today]
        ];
        $todayMoney = (new PlaceOrder())->getPlaceOrderByCount($where,'id,count(*) as count');
        $week_where = [
            ['create_time','between',Time::week()]
        ];
        $weekMoney = (new PlaceOrder())->getPlaceOrderByCount($week_where,'id,count(*) as count');
        $month_money = [
            ['create_time','between',Time::month()]
        ];
        $lastMonthWhere = (new PlaceOrder())->getPlaceOrderByCount($month_money,'id,count(*) as count');
        $year_money = [
            ['create_time','between',Time::year()]
        ];
        $yearMoney = (new PlaceOrder())->getPlaceOrderByCount($year_money,'id,count(*) as count');

        return $this->fetch('',[
            'todayMoney'=>$todayMoney['count'] ?? 0,
            'weekMoney'=>$weekMoney['count'] ?? 0,
            'lastMonthWhere'=>$lastMonthWhere['count'] ?? 0,
            'yearMoney'=>$yearMoney['count'] ?? 0,
        ]);
    }
}